home *** CD-ROM | disk | FTP | other *** search
- <?php
-
- /* Copyright (C) 2003 Adam Tow
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-
- function RunWithParams($methodName, $params)
- {
- $servicePath = $params["path_service"];
-
- include_once $servicePath . "support/mime_lookup.php";
- include_once $servicePath . "support/unicodeToEntities.php";
-
- switch($methodName)
- {
- case "file": return EditFile($params);
- break;
-
- case "cd":
- default: return ChangeDirectory($params);
- break;
-
-
- }
- }
-
- function ChangeDirectory($params)
- {
- $directory = $params["dir"];
- $showHidden = $params["showHidden"];
-
- if(!$directory)
- $directory = "/";
-
- //echo_object(0, $params, "Parameters");
-
- if(file_exists($directory) && is_dir($directory)) {
- $directory = realpath($directory);
-
- $len = strlen($directory);
-
- if(is_dir($directory) && $directory[$len - 1] != "/")
- $directory .= "/";
-
- $dir = @dir($directory);
- $directories = array();
- $files = array();
-
- //$userInfo = posix_getpwnam("adam");
- $userInfo = posix_getlogin();
-
- while($dir && false !== ($file = $dir->read())) {
- if($file != "." && $file != "..") {
- $type = @filetype(realpath($directory . $file));
-
-
- // Only handle directories and files
-
- $appPos = strpos($file, ".app");
- $len = strlen($file);
-
- $filename = utf8ToUnicodeEntities($file);
- //$filename = $file;
- //echo $filename . "<br />";
-
- if($type == "dir" && (!$appPos || $appPos != $len - 4)) {
- if($file[0] == "." && $showHidden)
- array_push($directories, array("name" => $filename, "file" => $file));
- else if($file[0] != ".")
- array_push($directories, array("name" => $filename, "file" => $file));
- } else if($type == "file" || ($type == "dir" && ($appPos == $len - 4))) {
- if($file[0] == "." && $showHidden)
- array_push($files, array("name" => $filename, "file" => $file));
- else if($file[0] != ".")
- array_push($files, array("name" => $filename, "file" => $file));
- }
- }
- }
-
- $response = array( "template" => "directory.tpl",
- "directories" => $directories,
- "files" => $files,
- "currentDir" => $directory,
- "user" => $userInfo,
- "params" => $params,
- );
-
- return ScriptResponse($response);
-
- } else if(file_exists($directory)) {
- $response = array(
- "template" => "file.tpl",
- "dir" => $params["currentDir"],
- "file" => $params["file"],
- "filename" => $params["filename"],
- );
-
- //echo_object(0, $response, "Response");
-
- return ScriptResponse($response);
-
- } else {
- return ScriptErrorResponse("", "File not found.");
- }
-
- return $response;
- }
-
-
- function EditFile($params)
- {
- $fileCmd = $params["fileCmd"];
- $directory = $params["dir"];
- $file = $params["file"];
- $filename = $params["filename"];
-
- $response = array(
- "template" => "file.tpl",
- "dir" => $directory,
- "file" => $file,
- "filename" => $filename,
- );
-
- if(!$fileCmd) {
-
-
- } else {
- $filePath = $directory . $file;
-
- switch($fileCmd) {
- /*
- case "print": //$result = exec("osascript -e 'tell application \"Finder\" to print alias (POSIX file \"$filePath\" as text)'");
- $result = exec("osascript -e 'tell application \"Finder\" to print alias (POSIX file \"$filePath\" as text)' -e 'return \"1\"'");
- //echo "Result: $result";
- if($result == 1) {
- $response["err"] = "print_success";
- } else {
- $response["err"] = "print_err";
- }
- break;
- */
- case "download": if(file_exists($filePath)) {
- if($fp = fopen($filePath, "r")) {
- $size = filesize($filePath);
- $fname = basename($filePath);
-
- header("Pragma: ");
- header("Cache-Control: ");
- header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"" . $fname . "\"");
- header("Content-length: $size");
-
- while(!feof($fp)) {
- $buffer = fread($fp, 2048);
- print $buffer;
- }
- fclose($fp);
- exit;
- }
- } else {
- die("File not found");
- }
-
- break;
-
- default: echo "$fileCmd<br />";
- break;
- }
- }
-
-
-
- return ScriptResponse($response);
- }
-
- ?>